package com.example.springboot.mapper;

import com.example.springboot.entity.Application;
import com.example.springboot.entity.Device;
import com.example.springboot.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ApplicationMapper {

    @Select("SELECT * from sys_application")
    List<Application> findAll();

    @Insert("insert into sys_application(device_id,utility,situation,note,applier_id,is_approve,approval_id) " +
            "VALUES (#{deviceId},#{utility},#{situation},#{note},#{applierId},#{isApprove},#{approvalId});")
    int insert(Application application);

    int update(Application application);

    @Select("select * from sys_application where is_approve like concat('%',#{isApprove},'%') limit #{pageNum},#{pageSize}")
    List<Application> selectPage(Integer pageNum, Integer pageSize, String isApprove);

    @Select("select count(*) from sys_application where is_approve like concat('%',#{isApprove},'%')")
    Integer selectTotal(String isApprove);

    @Update("update sys_application set is_approve = '已审批' where id= #{id}")
    int updateApprove(@Param("id")Integer id);

    @Update("update sys_application set approval_id = #{approvalId} where id= #{id}")
    int updateApproval(Integer id, Integer approvalId);

    @Select("SELECT * from sys_application where applier_id = #{applierId}")
    List<Application> findByUser(Integer applierId);

    @Select("SELECT * from sys_application where id = #{id}")
    List<Application> selectById(Integer id);

}
